package net.skyedu.service;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.skyedu.bean.SysCourse;
import net.skyedu.bean.SysOutline;
import net.skyedu.dao.DaoSupport;

public class DelCourse extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public DelCourse() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		int id = Integer.parseInt(request.getParameter("id"));
		
		DaoSupport ds = new DaoSupport();
		SysCourse sc = new SysCourse();
		SysOutline so = new SysOutline();
		sc.setCouId(id);
		so.setOutCouId(id);
		
		ds.delOutline(so);
		int num = ds.delCourse(sc);
		int flag = 0;
		if(num>0){
			flag = 1;
		}else{
			flag = 4;
		}
		
		 PrintWriter out = response.getWriter();
		 StringBuffer jsonAttr = new StringBuffer("[{");
		 jsonAttr.append("\"flag\":\""+flag+"\"");
		 jsonAttr.append("}]");
		 out.print(jsonAttr);
		 out.flush();
		 out.close();
	}

	public void init() throws ServletException {}

}
